import {Toast, Dialog} from 'vant';

export default class Loading {
  static bodyMove (ev) {
    ev.preventDefault()
  }

  static addPrevent() {
    document.querySelector('body').addEventListener('touchmove', this.bodyMove, {passive: false})
  }

  static clearPrevent() {
    document.querySelector('body').removeEventListener('touchmove', this.bodyMove, {passive: false})
  }

  static show(message) {
    let _msg = message || '加载中...';
    Toast.loading({
      duration: 0,       // 持续展示 toast
      forbidClick: true, // 禁用背景点击
      message: _msg
    });

    this.addPrevent()
  }

  static clear() {
    Toast.clear();
    this.clearPrevent()
  }


  static networkError() {
    Toast.fail({
      duration: 3000,
      message: '网络错误！'
    })
    this.addPrevent()
  }

  static DialogAlert(options) {
    return Dialog.alert(options)
  }
}
